from PIL import Image, ImageDraw, ImageFont

ori_graph = "./res/ori128_64.jpg"
ttf_file = "./resources/像素体.TTF"
output_dir = "./res"


def font():
    with Image.open(ori_graph) as base:
        txt = Image.new("1", base.size, 0)
        d = ImageDraw.Draw(txt)
        fnt = ImageFont.truetype(ttf_file, size=20)
        d.text((55, 20), text="弦", font=fnt, fill=1)
        # txt.show()
        txt.save(f"{output_dir}/xian.jpg")


def line():
    with Image.open(ori_graph) as base:
        im = Image.new("1", base.size, 0)
        draw = ImageDraw.Draw(im)
        draw.line((25, 40, 35, 40), 1)  # x+10
        draw.line((35, 40, 35, 25), 1)  # y-15
        draw.line((35, 25, 45, 25), 1)  # x+10
        draw.line((45, 25, 45, 40), 1)  # y+15
        draw.line((45, 40, 55, 40), 1)  # x+10
        draw.line((55, 40, 55, 25), 1)  # y-15
        draw.line((55, 25, 65, 25), 1)  # x+10
        draw.line((65, 25, 65, 40), 1)  # y+15
        draw.line((65, 40, 75, 40), 1)  # x+10
        draw.line((75, 40, 75, 25), 1)  # y-15
        draw.line((75, 25, 85, 25), 1)  # x+10
        draw.line((85, 25, 85, 40), 1)  # y+15
        draw.line((85, 40, 95, 40), 1)  # x+10
        # im.show()
        im.save(f"{output_dir}/square.jpg")


def wave():
    with Image.open(ori_graph) as base:
        im = Image.new("1", base.size, 0)
        draw = ImageDraw.Draw(im)
        draw.arc((25, 20, 35, 40), 0, 180, 1)  # 水平10，垂直20
        draw.arc((35, 20, 45, 40), 180, 0, 1)  # 水平移动10
        draw.arc((45, 20, 55, 40), 0, 180, 1)
        draw.arc((55, 20, 65, 40), 180, 0, 1)
        draw.arc((65, 20, 75, 40), 0, 180, 1)
        draw.arc((75, 20, 85, 40), 180, 0, 1)
        draw.arc((85, 20, 95, 40), 0, 180, 1)
        # im.show()
        im.save(f"{output_dir}/sine.jpg")


def guitar():
    with Image.open(ori_graph) as base:
        im = Image.new("1", base.size, 0)
        draw = ImageDraw.Draw(im)
        draw.rounded_rectangle((51, 37, 76, 59), radius=10, fill=1)
        draw.rectangle((57, 47, 70, 50), fill=0)
        draw.rounded_rectangle((52, 25, 74, 37), radius=7, fill=1)
        draw.rectangle((62, 4, 65, 47), fill=0)
        draw.rectangle((61, 4, 66, 24), fill=1)
        draw.rounded_rectangle((58, 33, 69, 42), radius=5, fill=0)
        draw.line((58, 5, 69, 5), 1)
        draw.line((58, 7, 69, 7), 1)
        draw.line((58, 9, 69, 9), 1)
        # im.show()
        im.save(f"{output_dir}/guitar.jpg")


def tri():
    with Image.open(ori_graph) as base:
        im = Image.new("1", base.size, 0)
        draw = ImageDraw.Draw(im)
        # draw.polygon(((25,36),(34,20),(43,36)),1)
        draw.line((25, 36, 34, 20), 1)
        draw.line((34, 20, 43, 36), 1)
        draw.line((43, 36, 53, 20), 1)
        draw.line((53, 20, 62, 36), 1)
        draw.line((62, 36, 72, 20), 1)
        draw.line((72, 20, 81, 36), 1)
        draw.line((81, 36, 91, 20), 1)
        draw.line((91, 20, 100, 36), 1)
        # im.show()
        im.save(f"{output_dir}/triangle.jpg")


def loading():
    with Image.open(ori_graph) as base:
        im = Image.new("1", base.size, 0)
        ttf = ImageFont.load_default()
        img_draw = ImageDraw.Draw(im)
        img_draw.text((35, 25), 'Loading...', font=ttf, fill=1)
        im.save(f"{output_dir}/loading.jpg")


def start():
    with Image.open(ori_graph) as base:
        im = Image.new("1", base.size, 0)
        ttf = ImageFont.load_default()
        img_draw = ImageDraw.Draw(im)
        img_draw.text((25, 25), 'You Can Start!', font=ttf, fill=1)
        im.save(f"{output_dir}/start.jpg")


def main():
    # font()
    # line()
    # wave()
    # guitar()
    # tri()
    # loading()
    start()


if __name__ == '__main__':
    main()
